﻿using System;
using System.Collections.Generic;

namespace Sgs.Utils
{
    static class Method
    {
        public static List<T> Shuffle<T>(List<T> list)
        {
            Random random = new Random();
            for (int i = 0; i < list.Count; i++)
            {
                int rand = random.Next(0, list.Count);
                T temp = list[i];
                list[i] = list[rand];
                list[rand] = temp;
            }
            return list;
        }

        public static T[] Shuffle<T>(T[] list)
        {
            Random random = new Random();
            for (int i = 0; i < list.Length; i++)
            {
                int rand = random.Next(0, list.Length);
                T temp = list[i];
                list[i] = list[rand];
                list[rand] = temp;
            }
            return list;
        }

        public static int SafeReadNumber()
        {
            string ReadLine = Console.ReadLine();
            try
            {
                int SafeNumber = int.Parse(ReadLine);
                return SafeNumber;
            }
            catch (FormatException)
            {
                Console.WriteLine("输入的数据不合理，请重新输入");
                return SafeReadNumber();
            }
        }
    }
}

